App({
  globalData: {
    userInfo: null,
    serverUrl: 'https://your-api-server.com',
    healthData: {
      heartRate: 72,
      bloodPressure: '120/80',
      bloodSugar: 5.6,
      steps: 6800
    }
  },

  onLaunch() {
    // 小程序启动时执行
    console.log('智慧养老小程序启动');
    
    // 检查登录状态
    this.checkLogin();
    
    // 获取用户健康数据
    this.getHealthData();
  },

  checkLogin() {
    const token = wx.getStorageSync('token');
    if (token) {
      // 验证token有效性
      this.getUserInfo();
    }
  },

  getUserInfo() {
    // 模拟获取用户信息
    this.globalData.userInfo = {
      id: 1,
      name: '张大爷',
      age: 68,
      phone: '138****8888',
      avatar: 'https://dummyimage.com/120x120/cccccc/888888.png&text=Avatar',
      emergencyContact: '李女士',
      emergencyPhone: '139****9999'
    };
  },

  getHealthData() {
    // 模拟获取健康数据
    // 实际应用中从服务器获取
    const healthData = wx.getStorageSync('healthData');
    if (healthData) {
      this.globalData.healthData = healthData;
    }
  },

  // 工具函数：格式化日期
  formatDate(date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
  },

  // 工具函数：显示提示
  showToast(title, icon = 'none') {
    wx.showToast({
      title,
      icon,
      duration: 2000
    });
  }
})
